package com.yunji.cabinet.engine;

import com.yunji.cabinet.cache.CabinetCache;
import com.yunji.cabinet.device.DeviceAssert;
import com.yunji.common.exception.device.DeviceErrorEnum;
import com.yunji.cabinet.domain.ContainerDO;
import com.yunji.cabinet.domain.DeviceBindDO;
import com.yunji.cabinet.enums.UseStatus;
import com.yunji.common.model.cache.ContainerTypeCacheDTO;
import com.yunji.common.utils.TimeUtils;
import com.yunji.common.utils.bean.BeanUtils;

/**
 * @author : peter-zhu
 * @date : 2025/1/15 11:38
 * @description : TODO
 **/
public class CabinetInitData {

    public static final String CABINET_DEFAULT_PREFIX = "柜";

    /**
     * @author : peter-zhu
     * @date : 2025/1/15 11:39
     * @description : 工厂测试启用后初始化数据
     */
    public static ContainerDO initByDevice(DeviceBindDO bind, String typeCode) {
        ContainerDO cabinet = new ContainerDO();
        cabinet.setContainerName(CABINET_DEFAULT_PREFIX + TimeUtils.dateTimeNow());
        cabinet.setTypeCode(typeCode);
        ContainerTypeCacheDTO containerType = CabinetCache.getContainerType(typeCode);
        DeviceAssert.isTrue(BeanUtils.isNotNull(containerType), DeviceErrorEnum.CHECKED_212509, bind.getImei());
        cabinet.setNums(containerType.getNums());
        cabinet.setQrcode(bind.getQrCode());
        cabinet.setChipImei(bind.getImei());
        cabinet.setChipSn(bind.getSn());
        cabinet.setUseStatus(UseStatus.DISUSE.getCode());
        cabinet.setDelFlag(0);
        return cabinet;
    }

}
